package org.hako.recite.word.words.impl;

import java.util.BitSet;
import java.util.Random;

/**
 * Random index handler for entire words.
 * 
 * @author xnnyygn
 */
public class EntireRandomIndexHandler extends AbstractRandomIndexHandler {

	public EntireRandomIndexHandler(int testWordLimit, int testWordRangeEnd) {
		this(testWordLimit, 0, testWordRangeEnd);
	}

	/**
	 * Create
	 * 
	 * @param testWordLimit
	 * @param testWordRangeStart
	 * @param testWordRangeEnd
	 */
	public EntireRandomIndexHandler(int testWordLimit, int testWordRangeStart,
			int testWordRangeEnd) {
		super(testWordLimit);
		BitSet bitSet = new BitSet(testWordRangeEnd);
		Random random = new Random();
		int rangeWidth = testWordRangeEnd - testWordRangeStart;
		for (int i = 0; i < testWordLimit; i++) {
			int value = -1;
			do {
				value = random.nextInt(rangeWidth) + testWordRangeStart;
			} while (bitSet.get(value));
			mirror[i] = value;
			bitSet.set(value);
		}
	}
}
